package com.file.manage.infrastructure.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页对象
 *
 * @author open-cld
 */
@Setter
@Getter
@Schema(title = "分页对象")
public class Pager<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(title = "总条数")
    private int totalProperty = 0;

    @Schema(title = "数据")
    private List<T> root = new ArrayList<>();

    public Pager() {
        super();
    }

    public Pager(Page<T> page) {
        super();
        this.totalProperty = Long.valueOf(page.getTotal()).intValue();
        this.root = page.getRecords();
    }

    public Pager(int totalProperty, List<T> root) {
        super();
        this.totalProperty = totalProperty;
        this.root = root;
    }

    public Pager(long totalProperty, List<T> root) {
        super();
        this.totalProperty = Long.valueOf(totalProperty).intValue();
        this.root = root;
    }

    public int getTotalProperty() {
        return totalProperty;
    }

    public List<T> getRoot() {
        return root;
    }

}
